package com.apache.flow.core.manager;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.apache.core.orm.Page;
import com.apache.flow.core.dao.FlowTaskUrlDao;
import com.apache.flow.core.entity.FlowTaskUrl;
import com.apache.flow.vo.FlowLockQvo;

@Service
@Transactional
public class FlowTaskUrlManager {
	@Autowired
	private FlowTaskUrlDao flowTaskUrlDao;

	/**
	 * 根据id得到资源
	 * @param id
	 * @return Lock
	 */
	@Transactional(readOnly = true)
	public FlowTaskUrl getFlowTaskUrl(String id) {
		return flowTaskUrlDao.get(id);
	}

	/**
	 * 获得所有任务
	 * @return List<FlowTaskUrl>
	 * @throws UctLockException 
	 */
	@Transactional(readOnly = true)
	public List<FlowTaskUrl> getAllTaskUrl() throws Exception {
		return flowTaskUrlDao.getAll();
	}

	/**
	 * 
	 * @param qvo
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * <p>@description 分页查询方法
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:59:08
	 */
	@Transactional(readOnly = true)
	public Page<FlowTaskUrl> getTaskUrlByVo(FlowLockQvo qvo, int pageNo, int pageSize) {
		return flowTaskUrlDao.getTaskUrlByVo(qvo, pageNo, pageSize);
	}

	/**
	 * 
	 * @param flowTaskUrl
	 * <p>@description 保存方法
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:59:22
	 */
	public void saveOrUpdateFlowTaskUrl(FlowTaskUrl flowTaskUrl) {
		flowTaskUrlDao.save(flowTaskUrl);
	}

	/**
	 * 
	 * @param propertyName
	 * @param value
	 * @return
	 * <p>@description 根据属性名查询对象
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:59:38
	 */
	@Transactional(readOnly = true)
	public FlowTaskUrl getFlowTaskUrlByPropertyName(String propertyName, String value) {
		return flowTaskUrlDao.findUniqueBy(propertyName, value);
	}

	/**
	 * 
	 * @param sysId
	 * @param taskName
	 * @return
	 * <p>@description 判断该系统下的资源名称是否已经存在
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:59:38
	 */
	@Transactional(readOnly = true)
	public List<FlowTaskUrl> checkTaskName(String sysId, String taskName) {
		String hql = "from FlowTaskUrl where sysId='" + sysId.trim() + "' and taskName='" + taskName.trim() + "'";
		return flowTaskUrlDao.find(hql);
	}

	/**
	 * 
	 * @param flowTaskUrl
	 * <p>@description 删除对象方法
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午05:00:00
	 */
	public void deleteFlowTaskUrl(FlowTaskUrl flowTaskUrl) {
		flowTaskUrlDao.delete(flowTaskUrl);
	}

	/**
	 * 
	 * @param sysId
	 * @return
	 * <p>@description 查询系统Id查询结果集
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午05:00:19
	 */
	@Transactional(readOnly = true)
	public List<FlowTaskUrl> getFlowTaskUrlBySysId(String sysId) {
		String hql = "from FlowTaskUrl where sysId='" + sysId.trim() + "'";
		return flowTaskUrlDao.find(hql);
	}

}
